package com.cy.shiro.util;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.Collection;
import java.util.List;

/**
 * 返回bootstrap数据表格参数
 * @param <T>
 */
@Data
@EqualsAndHashCode
public class ResultTableJson<T> {

    private T rows;
    private Integer total;
    private T parameter;

    public ResultTableJson(T rows, Integer total, T parameter) {
        this.rows = rows;
        this.total = total;
        this.parameter = parameter;
    }

    public String toJosn(){
        T t = this.getRows();
        if(t instanceof List || t instanceof Collection){
            return JSONObject.toJSONString(this, SerializerFeature.WriteNullListAsEmpty);
        } else {
            return JSONObject.toJSONString(this, SerializerFeature.WriteMapNullValue);
        }
    }
}
